<template>
    <div>
        <!--新增按钮位置-->
        <div style="position:fixed;z-index:100;width:100%">
            <div style="position:fixed;width:100%;padding: 2px;" class="van-cell--borderless van-contact-card">
                <van-dropdown-menu title="实训选择">
                    <van-dropdown-item v-model="classId" :options="classInfos" @change="changeClass" />
                </van-dropdown-menu>
            </div>
        </div>
        <!--列表展示位置-->
        <div v-show="show == 0">
            <div style="height: 73px"></div>
            <div v-for="(item,index) in resources" :item="item">
                <van-cell 
                    style="text-align: left;" center 
                    :title="item.name" 
                    :label="item.resourceType==0?'资源类型：文件':item.resourceUrl"
                    @click="copyUrl(item)">
                    <van-tag v-show="item.resourceType==0" 
                        @click="downLoadFile(item.resourceUrl)"
                        type="primary">下载</van-tag>
                </van-cell>
            </div>
            
        </div>
    </div>
</template>
<script>
import req from '../../request/index'
import {DownLoadFile} from '../../request/FileHttpRequestUtil'
export default {
    name: '',
    data() {
        return {
            showScore: false,
            show: 0,
            classInfos: [],
            classId: '',
            practiceTitle: '',
            resources: [],
        };
    },
    methods: {
        downLoadFile(url){
            DownLoadFile('/api/downfile',{'url':url})
        },
        copyUrl(resource){
            if(resource.resourceType==1){
                const ipt = document.createElement("input");
                ipt.value = resource.resourceUrl;
                document.body.appendChild(ipt);
                ipt.select();
                document.execCommand('Copy');
                ipt.remove();
                this.$notify({ type: 'success', message: '复制成功',duration: 1000, });
                //this.$dialog.alert({title:"已复制："+resource.resourceUrl})
            }
        },
        getResourcesList() {
            req({
                url: "getResourcesList",
                method: "post",
                data: {
                    relationClassId: this.classId
                }
            }).then(res => {
                this.resources = res.data.data
            }).catch(err => {
                console.log(err);
            })
        },
        getShixun() {
            req({
                url: "getShixun",
                method: "post",
                data: {
                    id: this.$store.state.user.id
                }
            }).then(res => {
                if (res.data.code == 0) {
                    var data = res.data.data;
                    this.classId = res.data.data[0].id;
                    this.practiceTitle = res.data.data[0].practiceTitle;
                    for (var i = 0; i < data.length; i++) {
                        var x = { text: '班级1', value: 0 };
                        x.text = data[i].practiceTitle;
                        x.value = data[i].id;
                        this.classInfos.push(x);
                    }
                    this.getResourcesList();
                }
            }).catch(err => {
                console.log(err);
            })
        },
        changeClass(res) {
            console.log(res)
            //根据班级id获取当前的所有任务信息
            for (var i = 0; i < this.classInfos.length; i++) {
                if (this.classInfos[i].value == res) {
                    this.practiceTitle = this.classInfos[i].text;
                    this.getResourcesList();
                }
            }
        },
    },
    computed: {
    },
    mounted() {
        //发送请求 获取该用户的所有班级信息
        this.getShixun();
    },
}
</script>
<style>
.van-dropdown-menu__bar {
    height: 68px;
}
</style>